Apply proper locking in xenlinux mtrr interface functions.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 9 Mar 2006 14:59:53 +0000 (15:59 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 9 Mar 2006 14:59:53 +0000 (15:59 +0100)
From: Jan Beulich
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c

index 407cc78b7c40ca6e3a38de5663ae8eb6bf97ad9f..8f09bd7b8d7e86657f5e723d7b9340d290fc8465 100644 (file)
@@ -8,6 +8,8 @@
 #include <asm/mtrr.h>
 #include "mtrr.h"
 
+static DECLARE_MUTEX(mtrr_sem);
+
 void generic_get_mtrr(unsigned int reg, unsigned long *base,
                      unsigned int *size, mtrr_type * type)
 {
@@ -63,12 +65,15 @@ int mtrr_add_page(unsigned long base, unsigned long size,
        int error;
        dom0_op_t op;
 
+       down(&mtrr_sem);
+
        op.cmd = DOM0_ADD_MEMTYPE;
        op.u.add_memtype.mfn     = base;
        op.u.add_memtype.nr_mfns = size;
        op.u.add_memtype.type    = type;
        error = HYPERVISOR_dom0_op(&op);
        if (error) {
+               up(&mtrr_sem);
                BUG_ON(error > 0);
                return error;
        }
@@ -76,6 +81,8 @@ int mtrr_add_page(unsigned long base, unsigned long size,
        if (increment)
                ++usage_table[op.u.add_memtype.reg];
 
+       up(&mtrr_sem);
+
        return op.u.add_memtype.reg;
 }
 
@@ -104,17 +111,18 @@ mtrr_add(unsigned long base, unsigned long size, unsigned int type,
 
 int mtrr_del_page(int reg, unsigned long base, unsigned long size)
 {
-       int i, max;
+       unsigned i;
        mtrr_type ltype;
        unsigned long lbase;
        unsigned int lsize;
        int error = -EINVAL;
        dom0_op_t op;
 
-       max = num_var_ranges;
+       down(&mtrr_sem);
+
        if (reg < 0) {
                /*  Search for existing MTRR  */
-               for (i = 0; i < max; ++i) {
+               for (i = 0; i < num_var_ranges; ++i) {
                        mtrr_if->get(i, &lbase, &lsize, &ltype);
                        if (lbase == base && lsize == size) {
                                reg = i;
@@ -143,6 +151,7 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)
        }
        error = reg;
  out:
+       up(&mtrr_sem);
        return error;
 }